

class Menu{
    constructor(name,id){
        this.name = name
        this.id = id 
        // this.parentId = 
        //多态形式处理，泛型Menu
        // ArrayList<Menu>()
        this.menuList = []
    }
    addMenu(menu){
        this.menuList.push(menu)
        return this
    }
    removeMenu(menu){
        // this.menuList.splice()
        this.menuList = this.menuList.filter(ele=> ele.id!==menu.id)
    }
    getAllMenu(){
        return this.menuList
    }
}

const mainMenu = new Menu("管理部",1)
const subMenu = new Menu("科技产品部",2)
const subMenu2 = new Menu("智能云部",2)
const thirdMenu = new Menu("电子渠道",3)
const thirdMenu2 = new Menu("财富业务",3)
mainMenu.addMenu(subMenu).addMenu(subMenu2)
subMenu.addMenu(thirdMenu).addMenu(thirdMenu2)

let line = "="
function getList(menu){
    console.log(line,menu.name)
    menu.getAllMenu().forEach(element => {
        if(element.getAllMenu().length>0){
            getList(element)
        }else{
            console.log(line,element.name)
        }
    });}

getList(mainMenu)

